package com.wwu.system.controller;

import com.wwu.common.constant.CommConst;
import com.wwu.common.web.ResultObj;
import com.wwu.common.web.ResultPage;
import com.wwu.system.entity.SysUser;
import com.wwu.system.service.IOnlineUserService;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 在线用户前端控制器
 * @author 一蓑烟雨
 * @version 1.0.0
 * @date 2023-07-26 09:06
 */
@Api(tags = "在线用户控制器(OnlineUserController)")
@ApiSort(5)
@Controller
@RequestMapping("/system/online")
public class OnlineUserController {
    @Resource
    private IOnlineUserService onlineUserService;

    /**
     * 请求转发到在线用户主页
     * @return java.lang.String
     * @author 一蓑烟雨
     * @date 2023/7/26 16:19
     */
    @GetMapping("/onlineUserMain")
    public String onlineUserMainHtml() {
        return "system/online/online-user-main";
    }

    @ApiOperation(value = "查询在线用户信息")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页数",paramType = "query", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数",paramType = "query", required = true),
            @ApiImplicitParam(name = "userName", value = "用户名"),
            @ApiImplicitParam(name = "loginIp", value = "登陆地址")
    })
    @GetMapping("/userList")
    @ResponseBody
    public ResultPage<SysUser> userList(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "5000") Integer limit,
                                        String userName,
                                        String loginIp) {
        return onlineUserService.getOnlineUserListPage(page,limit,userName,loginIp);
    }

    @ApiOperation(value = "踢出登陆用户")
    @ApiOperationSupport(order = 2)
    @DeleteMapping("/pickOutUser/{sessionIds}")
    @ResponseBody
    public ResultObj pickOutUser(@ApiParam(name = "sessionIds", value = "会话id集合，以逗号分隔", required = true)
                                 @PathVariable String sessionIds){
        onlineUserService.pickOutUser(Arrays.asList(sessionIds.split(CommConst.SPLIT_COMMA)));
        return ResultObj.success("用户踢出登陆成功");
    }
}
